//package cn.nexd.map.algorithm;
//
//
//import android.app.Activity;
//import android.content.res.AssetManager;
//
//import org.json.JSONArray;
//import org.json.JSONException;
//import org.json.JSONObject;
//
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//
//import cn.nexd.map.location.utils.Log;
//
///**
// * Created by admin on 15/8/15.
// */
//
////class NB_Classifier{
////    public List<Double> prior;
////    public List<List<Double>> post_mean;
////    public List<List<Double>>  post_var;
////    public List<List<Double>>  res_pos;
////}
//
//
//public class ConfLoader extends Activity {
//    public NB_Classifier Load(String conf_file) throws IOException, JSONException {
//        return _Load(conf_file);
//    }
//
//    public NB_Classifier Load_Stream(InputStream inputStream) throws IOException, JSONException {
//        return parse_json(_convertString(inputStream));
//    }
//
//    private String _convertString(InputStream inputStream) throws IOException {
//        StringBuilder stringBuilder = new StringBuilder();
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//        boolean firstLine = true;
//        String line = null;
//        ;
//        while ((line = bufferedReader.readLine()) != null) {
//            if (!firstLine) {
//                stringBuilder.append(System.getProperty("line.separator"));
//            } else {
//                firstLine = false;
//            }
//            stringBuilder.append(line);
//        }
//        System.out.println(stringBuilder.toString());
//        return stringBuilder.toString();
//    }
//
//    private NB_Classifier _Load(String conf_file) throws IOException, JSONException {
//        return parse_json(getConfJson(conf_file));
//    }
//
//    private NB_Classifier parse_json(String jsonstr) throws JSONException {
//        JSONObject obj = new JSONObject(jsonstr);
//        JSONArray prior = obj.getJSONArray("Prior");
//        NB_Classifier clf = new NB_Classifier();
//        //        int wifi_length = prior.length();
//
//
//        clf.prior = new Double[prior.length()];
//        for (int i = 0; i < prior.length(); i++) {
//            clf.prior[i] = prior.getDouble(i);
//        }
//
//        JSONArray post_param = obj.getJSONArray("Post_param");
//
//        int block_size = post_param.length();
//        JSONObject temp = post_param.getJSONObject(0);
//        JSONArray mean = temp.getJSONArray("Mean");
//        int wifi_length = mean.length();
//        clf.post_mean = new Double[block_size][wifi_length];
//        clf.post_var = new Double[block_size][wifi_length];
//        clf.res_pos = new Double[block_size][2];
//        clf.wifi_list = new String[wifi_length];
//
//        for (int i = 0; i < block_size; i++) {
//            temp = post_param.getJSONObject(i);
//            mean = temp.getJSONArray("Mean");
//            JSONArray var = temp.getJSONArray("Sigma");
//            for (int j = 0; j < wifi_length; j++) {
//                clf.post_var[i][j] = var.getDouble(j);
//                clf.post_mean[i][j] = mean.getDouble(j);
//            }
//        }
//
//        JSONArray pos = obj.getJSONArray("Pos");
//        for (int i = 0; i < block_size; i++) {
//            JSONArray p = pos.getJSONArray(i);
//            clf.res_pos[i][0] = p.getDouble(0);
//            clf.res_pos[i][1] = p.getDouble(1);
//        }
//
//        JSONArray wifi_list = obj.getJSONArray("Wifi_List");
//        for (int i = 0; i < wifi_length; i++) {
//            clf.wifi_list[i] = wifi_list.getString(i);
//        }
//        return clf;
//    }
//
//    private InputStream _loadAssetsConf(AssetManager assetMngr, String confPath) throws IOException {
//        return assetMngr.open(confPath);
//    }
//
//    private String getConfJson(String conf_file) throws IOException {
//        String conf_file_path = conf_file + ".conf";
//        Log.d("onConfLoading", "Loading  :  " + conf_file_path);
//
//        InputStream inputStream = _loadAssetsConf(this.getAssets(), conf_file_path);
//        StringBuilder stringBuilder = new StringBuilder();
//        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//        boolean firstLine = true;
//        String line = null;
//        ;
//        while ((line = bufferedReader.readLine()) != null) {
//            if (!firstLine) {
//                stringBuilder.append(System.getProperty("line.separator"));
//            } else {
//                firstLine = false;
//            }
//            stringBuilder.append(line);
//        }
//        System.out.println(stringBuilder.toString());
//        return stringBuilder.toString();
//    }
//
//
//}
